/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.app.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yanlight.Constants;
import com.yanlight.app.request.ShopMembeRegisterRequest;
import com.yanlight.app.service.ShopMemberService;
import com.yanlight.support.http.Response;
import com.yanlight.util.CookieUtil;
import com.yanlight.util.ResponseUtil;
import com.yanlight.util.WebUtil;

/**
 * 
 * @author haolw
 * @time 2018/01/04
 */
@RestController
@RequestMapping("/member")
public class ShopMemberController {
	@Autowired
	private ShopMemberService shopMemberService;

	@PostMapping("/register")
	public Response register(HttpServletRequest httpRequest, ShopMembeRegisterRequest request) {
		if (WebUtil.isAlipayBrowse(httpRequest)) {
			String aliUserid = CookieUtil.getValue(httpRequest, Constants.ALIPAY_USER_ID);
			request.setAlipayUserid(aliUserid);
		} else if (WebUtil.isWxBrowse(httpRequest)) {
			String wxOpenid = CookieUtil.getValue(httpRequest, Constants.WX_OPENID);
			request.setWxOpenid(wxOpenid);
		}
		shopMemberService.register(request);
		return ResponseUtil.success();
	}
}
